

class UserInfoController {
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        [ userInfoInstanceList: UserInfo.list( params ), userInfoInstanceTotal: UserInfo.count() ]
    }

    def show = {
        def userInfoInstance = UserInfo.get( params.id )
        if(!userInfoInstance) {
            flash.message = "UserInfo not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ userInfoInstance : userInfoInstance ] }
    }

    def delete = {
        def userInfoInstance = UserInfo.get( params.id )
        if(userInfoInstance) {
            try {
                userInfoInstance.delete(flush:true)
                flash.message = "UserInfo ${params.id} deleted"
                redirect(action:list)
            }
            catch(org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "UserInfo ${params.id} could not be deleted"
                redirect(action:show,id:params.id)
            }
        }
        else {
            flash.message = "UserInfo not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def userInfoInstance = UserInfo.get( params.id )

        if(!userInfoInstance) {
            flash.message = "UserInfo not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ userInfoInstance : userInfoInstance ]
        }
    }

    def update = {
        def userInfoInstance = UserInfo.get( params.id )
        if(userInfoInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(userInfoInstance.version > version) {
                    
                    userInfoInstance.errors.rejectValue("version", "userInfo.optimistic.locking.failure", "Another user has updated this UserInfo while you were editing.")
                    render(view:'edit',model:[userInfoInstance:userInfoInstance])
                    return
                }
            }
            userInfoInstance.properties = params
            if(!userInfoInstance.hasErrors() && userInfoInstance.save()) {
                flash.message = "UserInfo ${params.id} updated"
                redirect(action:show,id:userInfoInstance.id)
            }
            else {
                render(view:'edit',model:[userInfoInstance:userInfoInstance])
            }
        }
        else {
            flash.message = "UserInfo not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def create = {
        def userInfoInstance = new UserInfo()
        userInfoInstance.properties = params

        return ['userInfoInstance':userInfoInstance]
    }

    def save = {
        def userInfoInstance = new UserInfo(params)
         userInfoInstance.type="3"  ;
        if(!userInfoInstance.hasErrors() && userInfoInstance.save()) {
            flash.message = "UserInfo ${userInfoInstance.id} created"
            redirect(action:show,id:userInfoInstance.id)
        }
        else {
            render(view:'create',model:[userInfoInstance:userInfoInstance])
        }
    }
}
